import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_click_widget.dart';
import 'package:baselib/widgets/comm_password_textfield.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:baselib/widgets/nosize_app_bar.dart';
import 'package:baselib/widgets/simple_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_comm/viewmodel/login_email_view_model.dart';
import 'package:module_business/module_comm/viewmodel/register_info_view_model.dart';
import 'package:module_business/module_comm/viewmodel/register_select_favorite_view_model.dart';
import 'package:module_business/module_comm/viewmodel/register_view_model.dart';
/**
 * 注册选择兴趣主页
 */
class RegisterSelectFavoritePage extends GetWidget<RegisterSelectFavoriteViewModel> {
  @override
  Widget build(BuildContext context) {
    return PageWidget.build(
        builder: (RegisterSelectFavoriteViewModel model){
          return PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              backgroundColor: ColorUtil.instance.color_transparent,
              actionName: StringUtil.instance.Skip,
              actionNameTextStyle: TextStyle(
                fontSize: PxUtil.instance.px_16,
                color: ColorUtil.instance.color_white,
                fontWeight: FontWeight.bold
              ),
              onActionPressed: ()=>model.toSkip(),
            ),
            bottomNavigationBar: Container(
              child: Container(
                margin: EdgeInsets.only(
                  top: PxUtil.instance.px_2,
                  bottom: PxUtil.instance.px_10,
                  left: PxUtil.instance.px_20,
                  right: PxUtil.instance.px_20,
                ),
                child: MainGradientButton(
                  onPressed: ()=>model.toStart(),
                  isImg: true,
                  imgPath: DrawableUtil.instance.icon_Start,
                  imgWidth: PxUtil.instance.px_46,
                ),
              ),
            ),
            body: Container(
              width: PxUtil.instance.screenWidth,
              height: PxUtil.instance.screenHeight-PxUtil.instance.statusBarHeight
                  -PxUtil.instance.appBarHeight,
              padding: EdgeInsets.only(
                left: PxUtil.instance.px_15,
                right: PxUtil.instance.px_15,
              ),
              child: _buildMiddleContUi(model),
            ),
          );
        }
    );
  }

  _buildMiddleContUi(RegisterSelectFavoriteViewModel model) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        SizedBox(height: PxUtil.instance.px_46,),
        GradientTextWidget(
          txt: StringUtil.instance.Select_your_favorite_interest_tag,
          txtStyle: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: PxUtil.instance.px_16,
          ),
        ),
        SizedBox(height: PxUtil.instance.px_12,),
        Text(
          StringUtil.instance.register_select_favorite_point,
          style: TextStyle(
            fontSize: PxUtil.instance.px_11,
            color: ColorUtil.instance.color_d8d8d8
          ),
        ),
        GridView.builder(
            shrinkWrap: true,
            padding: EdgeInsets.only(
              top: PxUtil.instance.px_35,
              bottom: PxUtil.instance.px_35,
              left: PxUtil.instance.px_10,
              right: PxUtil.instance.px_10,
            ),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
                mainAxisSpacing:30,
                crossAxisSpacing: 30,
                childAspectRatio: 1
            ),
            itemCount: model.types.length,
            itemBuilder: (BuildContext context,int index){
              var typeItem = model.types[index];
              return InkWellButton(
                onPressed: ()=>model.onItemPressed(index),
                child: Container(
                  child: Column(
                    children: [
                      Stack(
                        children: [
                          ImagesUtil.loadAssetImage(
                              typeItem.imgPath
                          ),
                          Positioned(
                              right: PxUtil.instance.px_26,
                              bottom: PxUtil.instance.px_26,
                              child: ImagesUtil.loadAssetImage(
                                (typeItem.selected??false)?DrawableUtil.instance.icon_selected:
                                    DrawableUtil.instance.icon_unselected,
                                width: PxUtil.instance.px_14,
                              )
                          )
                        ],
                      ),
                      Text(
                        typeItem.name,
                        style: TextStyle(
                            color: ColorUtil.instance.color_white,
                            fontWeight: FontWeight.bold,
                            fontSize: PxUtil.instance.px_12
                        ),
                      )
                    ],
                  ),
                ),
              );
            }
        )
      ],
    );
  }

}
